home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251812_mod_include.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-10-29  |  11.7 KB  |  239 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * Portions of this software are based upon public domain software
  55.  * originally written at the National Center for Supercomputing Applications,
  56.  * University of Illinois, Urbana-Champaign.
  57.  */
  58.  
  59. #ifndef _MOD_INCLUDE_H
  60. #define _MOD_INCLUDE_H 1
  61.  
  62. #include "apr_pools.h"
  63. #include "apr_optional.h"
  64.  
  65. #define STARTING_SEQUENCE "<!--#"
  66. #define ENDING_SEQUENCE "-->"
  67.  
  68. #define DEFAULT_ERROR_MSG "[an error occurred while processing this directive]"
  69. #define DEFAULT_TIME_FORMAT "%A, %d-%b-%Y %H:%M:%S %Z"
  70. #define SIZEFMT_BYTES 0
  71. #define SIZEFMT_KMG 1
  72. #define TMP_BUF_SIZE 1024
  73. #if APR_CHARSET_EBCDIC
  74. #define RAW_ASCII_CHAR(ch)  apr_xlate_conv_byte(ap_hdrs_from_ascii, (unsigned char)ch)
  75. #else /*APR_CHARSET_EBCDIC*/
  76. #define RAW_ASCII_CHAR(ch)  (ch)
  77. #endif /*APR_CHARSET_EBCDIC*/
  78.  
  79. /****************************************************************************
  80.  * Used to keep context information during parsing of a request for SSI tags.
  81.  * This is especially useful if the tag stretches across multiple buckets or
  82.  * brigades. This keeps track of which buckets need to be replaced with the
  83.  * content generated by the SSI tag.
  84.  *
  85.  * state: PRE_HEAD - State prior to finding the first character of the 
  86.  *                   STARTING_SEQUENCE. Next state is PARSE_HEAD.
  87.  *        PARSE_HEAD - State entered once the first character of the
  88.  *                     STARTING_SEQUENCE is found and exited when the
  89.  *                     the full STARTING_SEQUENCE has been matched or
  90.  *                     a match failure occurs. Next state is PRE_HEAD
  91.  *                     or PARSE_TAG.
  92.  *        PARSE_TAG - State entered once the STARTING sequence has been
  93.  *                    matched. It is exited when the first character in
  94.  *                    ENDING_SEQUENCE is found. Next state is PARSE_TAIL.
  95.  *        PARSE_TAIL - State entered from PARSE_TAG state when the first
  96.  *                     character in ENDING_SEQUENCE is encountered. This
  97.  *                     state is exited when the ENDING_SEQUENCE has been
  98.  *                     completely matched, or when a match failure occurs.
  99.  *                     Next state is PARSE_TAG or PARSED.
  100.  *        PARSED - State entered from PARSE_TAIL once the complete 
  101.  *                 ENDING_SEQUENCE has been matched. The SSI tag is
  102.  *                 processed and the SSI buckets are replaced with the
  103.  *                 SSI content during this state.
  104.  * parse_pos: Current matched position within the STARTING_SEQUENCE or
  105.  *            ENDING_SEQUENCE during the PARSE_HEAD and PARSE_TAIL states.
  106.  *            This is especially useful when the sequence spans brigades.
  107.  * X_start_bucket: These point to the buckets containing the first character
  108.  *                 of the STARTING_SEQUENCE, the first non-whitespace
  109.  *                 character of the tag, and the first character in the
  110.  *                 ENDING_SEQUENCE (head_, tag_, and tail_ respectively).
  111.  *                 The buckets are kept intact until the PARSED state is
  112.  *                 reached, at which time the tag is consolidated and the
  113.  *                 buckets are released. The buckets that these point to
  114.  *                 have all been set aside in the ssi_tag_brigade (along
  115.  *                 with all of the intervening buckets).
  116.  * X_start_index: The index points within the specified bucket contents
  117.  *                where the first character of the STARTING_SEQUENCE,
  118.  *                the first non-whitespace character of the tag, and the
  119.  *                first character in the ENDING_SEQUENCE can be found
  120.  *                (head_, tag_, and tail_ respectively).
  121.  * combined_tag: Once the PARSED state is reached the tag is collected from
  122.  *               the bucket(s) in the ssi_tag_brigade into this contiguous
  123.  *               buffer. The buckets in the ssi_tag_brigade are released
  124.  *               and the tag is processed.
  125.  * curr_tag_pos: Ptr to the combined_tag buffer indicating the current
  126.  *               parse position.
  127.  * tag_length: The number of bytes in the actual tag (excluding the
  128.  *             STARTING_SEQUENCE, leading and trailing whitespace,
  129.  *             and ENDING_SEQUENCE). This length is computed as the
  130.  *             buckets are parsed and set aside during the PARSE_TAG state.
  131.  * ssi_tag_brigade: The temporary brigade used by this filter to set aside
  132.  *                  the buckets containing parts of the ssi tag and headers.
  133.  */
  134. typedef enum {PRE_HEAD, PARSE_HEAD, PARSE_DIRECTIVE, PARSE_TAG, PARSE_TAIL, PARSED} states;
  135.  
  136. /** forward referenced as it needs to be held on the context */
  137. typedef struct bndm_t bndm_t;
  138.  
  139. typedef struct include_filter_ctx {
  140.     states       state;
  141.     long         flags;    /* See the FLAG_XXXXX definitions. */
  142.     int          if_nesting_level;
  143.     apr_size_t   parse_pos;
  144.     int          bytes_parsed;
  145.     apr_status_t status;
  146.     int          output_now;
  147.     int          output_flush;
  148.     
  149.     apr_bucket   *head_start_bucket;
  150.     apr_size_t   head_start_index;
  151.  
  152.     apr_bucket   *tag_start_bucket;
  153.     apr_size_t   tag_start_index;
  154.  
  155.     apr_bucket   *tail_start_bucket;
  156.     apr_size_t   tail_start_index;
  157.  
  158.     char        *combined_tag;
  159.     char        *curr_tag_pos;
  160.     apr_size_t   directive_length;
  161.     apr_size_t   tag_length;
  162.  
  163.     char         *error_str;
  164.     char         *error_str_override;
  165.     char         *time_str;
  166.     char         *time_str_override;
  167.     apr_pool_t   *pool;
  168.  
  169.     apr_bucket_brigade *ssi_tag_brigade;
  170.     bndm_t       *start_seq_pat;
  171.     char         *start_seq;
  172.     int          start_seq_len;
  173.     char         *end_seq;
  174.     char         *re_string;
  175.     regmatch_t   (*re_result)[10];
  176. } include_ctx_t;
  177.  
  178. /* These flags are used to set flag bits. */
  179. #define FLAG_PRINTING         0x00000001  /* Printing conditional lines. */
  180. #define FLAG_COND_TRUE        0x00000002  /* Conditional eval'd to true. */
  181. #define FLAG_SIZE_IN_BYTES    0x00000004  /* Sizes displayed in bytes.   */
  182. #define FLAG_NO_EXEC          0x00000008  /* No Exec in current context. */
  183.  
  184. /* These flags are used to clear flag bits. */
  185. #define FLAG_SIZE_ABBREV      0xFFFFFFFB  /* Reset SIZE_IN_BYTES bit.    */
  186. #define FLAG_CLEAR_PRINT_COND 0xFFFFFFFC  /* Reset PRINTING and COND_TRUE*/
  187. #define FLAG_CLEAR_PRINTING   0xFFFFFFFE  /* Reset just PRINTING bit.    */
  188.  
  189. #define CREATE_ERROR_BUCKET(cntx, t_buck, h_ptr, ins_head)        \
  190. {                                                                 \
  191.     /* XXX: it'd probably be nice to use a pool bucket here */    \
  192.     t_buck = apr_bucket_heap_create(cntx->error_str,              \
  193.                                     strlen(cntx->error_str),      \
  194.                                     NULL, h_ptr->list);           \
  195.     APR_BUCKET_INSERT_BEFORE(h_ptr, t_buck);                      \
  196.                                                                   \
  197.     if (ins_head == NULL) {                                       \
  198.         ins_head = t_buck;                                        \
  199.     }                                                             \
  200. }
  201.  
  202. /* Make sure to check the return code rc. If it is anything other
  203.  *   than APR_SUCCESS, then you should return this value up the
  204.  *   call chain.
  205.  */
  206. #define SPLIT_AND_PASS_PRETAG_BUCKETS(brgd, cntxt, next, rc)          \
  207. if ((APR_BRIGADE_EMPTY((cntxt)->ssi_tag_brigade)) &&                  \
  208.     ((cntxt)->head_start_bucket != NULL)) {                           \
  209.     apr_bucket_brigade *tag_plus;                                     \
  210.                                                                       \
  211.     tag_plus = apr_brigade_split((brgd), (cntxt)->head_start_bucket); \
  212.     if ((cntxt)->output_flush) {                                      \
  213.         APR_BRIGADE_INSERT_TAIL((brgd), apr_bucket_flush_create((brgd)->bucket_alloc));   \
  214.     }                                                                 \
  215.     (rc) = ap_pass_brigade((next), (brgd));                           \
  216.     (cntxt)->bytes_parsed = 0;                                        \
  217.     (brgd) = tag_plus;                                                \
  218. }
  219.  
  220.  
  221. typedef int (include_handler_fn_t)(include_ctx_t *ctx, apr_bucket_brigade **bb,
  222.                        request_rec *r, ap_filter_t *f, apr_bucket *head_ptr, 
  223.                        apr_bucket **inserted_head);
  224.  
  225. APR_DECLARE_OPTIONAL_FN(void, ap_ssi_get_tag_and_value, (include_ctx_t *ctx,
  226.                                                          char **tag,
  227.                                                          char **tag_val,
  228.                                                          int dodecode));
  229. APR_DECLARE_OPTIONAL_FN(char*, ap_ssi_parse_string, (request_rec *r,
  230.                                                     include_ctx_t *ctx,
  231.                                                     const char *in,
  232.                                                     char *out,
  233.                                                     apr_size_t length,
  234.                                                     int leave_name));
  235. APR_DECLARE_OPTIONAL_FN(void, ap_register_include_handler, 
  236.                         (char *tag, include_handler_fn_t *func));
  237.  
  238. #endif /* MOD_INCLUDE */
  239.